package com.example.entity;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: wyp
 * @Date: 2021/9/7 14:56
 */
public class Data {
//    public int data = 0 ;
    private volatile int data = 0 ;


    public void setData(int data){
        this.data = data;
    }

    public int getData() {
        return data;
    }

    public void addData(){
        this.data++;
    }

    //为了保证原子性
    private AtomicInteger atomicInteger = new AtomicInteger();

    public void addAtomic(){
        atomicInteger.getAndIncrement();
    }

    public AtomicInteger getAtomicInteger() {
        return atomicInteger;
    }

    public void setAtomicInteger(AtomicInteger atomicInteger) {
        this.atomicInteger = atomicInteger;
    }
}
